1.定义一个人员类Person,包括姓名、编号、性别等数据成员和用于输入、输出的成员函数,在此基础上派生出学生类Student类(增加成绩)和教师类Teacher(增加教龄),并实现对学生和教师信息的

#include <iostream>
#include<string.h>
using namespace std;
class  person
{   private:
    string name,sex;
    int number;
    public:
    void setperson(string n,string s,int nu)
    {
        name = n;
        sex = s;
        number = nu;
    }
    void output();
};
void person::output()
{
    cout<<"name: "<<name<<endl;
    cout<<"sex: "<<sex<<endl;
    cout<<"number: "<<number<<endl;
}
class student:public person
{
    private:
    int grade;
    public:
    student(){}
    student(string n,string s,int nu,int g)
    {
        person::setperson(n,s,nu);
        grade=g;
    }
   void output()
   {
       person::output();
       cout<<"grade: "<<grade<<endl;
   }
};
class teacher:public person
{
    private:
    int teachage;
    public:
    teacher(){}
    teacher(string n,string s,int nu,int t)
    {
        person::setperson(n,s,nu);
       teachage=t ;
    }
   void output()
   {
       person::output();
       cout<<"teachage: "<<teachage<<endl;
   }
};
int main()
{
    student m("李磊","男",16064,100);
    m.output();
     teacher n("赵宝宝","男",1141,20);
    n.output();
}



  • 13
    点赞
  • 82
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值